<?php

namespace App\Traits\Templates;

// 前台出单 对应型号 w1
trait FrontTemplate
{
	protected $frontData = [
        'detail' => [
            'store_name' => '门店名称',
            'created_at' => '2020/11/9 12:00',
            'count_man' => '12',
            'name' => '杰哥',
            'number' => 'no1145141919108',
            'cashier' => '阿伟',
            'print_count' => '1',
            'consumption_time' => '3小时3分',
            'room_type' => '中型房',
            'date' => '2020年11月9日',
            'time' => '12:00-15:03',
            'price' => '1046',
            'receive_price' => '1036',
            'uncollected_price' => '0',
            'pay_type' => '现金',
            'refund_price' => 0.00//找零
        ],
        'setmeal' => [
            'price' => '1000'
        ],
        'set_meals_to_goods' => [
            [
                'name' => '冰啤酒',
                'price' => '12',
                'number' => 1
            ],
            [
                'name' => '百威',
                'price' => '8',
                'number' => 2,
            ]
        ],
        'send_goods' => [
            'name' => '百威',
            'price' => '8',
            'number' => 2,
        ]
    ];
	// 文本主体
	public function FrontContent($data = [])
	{
		// 头部<LR>,</LR>
		// <table><tr><td>列1</td><td>列2</td><td>列3</td><td>列4</td></tr></table>
		$heads  = '<LR>@@2'.$data['detail']['store_name'].','.$data['detail']['created_at'].'</LR>';
		$heads .= '<LR>人 数:13,订房人员:'.$data['detail']['name'].'</LR>';
		$heads .= '<LR>账单编号:'.$data['detail']['number'].',结账人员:'.$data['detail']['cashier'].'</LR>';
		$heads .= '<LR>卡 头 号:123456,打印次数:1</LR>';
		$heads .= '<LR>消费时长:'.$data['detail']['consumption_time'].',房型:'.$data['detail']['room_type'].'</LR>';
		$heads .= '<LR>日期:'.$data['detail']['date'].',时间:'.$data['detail']['time'].'</LR>';
		$heads .= '<center>----------------------------------------</center>';
		$heads .= '<table><tr><td>项目</td><td>数量</td><td>单位</td><td>价格</td><td>金额</td></tr></table>';
		$heads .= '<center>----------------------------------------</center>';
		$heads .= '<LR>酒水包段:'.$data['detail']['consumption_time'].','.$data['setmeal']['price'].'</LR>';
		$heads .= '<center>----------------------------------------</center>';

		// 房费小计
		$room   = '<LR>房费小计:, '.$data['setmeal']['price'].'</LR>';
		// 消费小计
		$order  = '<center>----------------------------------------</center>';
		$order .= '<table>';
		if(isset($data['set_meals_to_goods']) && !empty($data['set_meals_to_goods'])) {
			foreach ($data['set_meals_to_goods'] as $k => $v) {
			$order .= '<tr><td>'.$v['name'].'</td><td>'.$v['number'].'</td><td>份</td><td>0</td><td>'.$v['price'].'</td></tr>';
			}
		} else {
			$order .= '<tr><td>无</td></tr>';
		}
		$order .= '</table>';
		// $order .= '哈尔冰/百威2打 1 套 0 0';
		// $order .= '百威（罐）24 罐 16 46' ;
		$order .= '<center>----------------------------------------</center>';
		$order .= '<LR>消费小计,46</LR>';
		$order .= '<center>----------------------------------------</center>';
		
		if(isset($data['send_goods']) && !empty($data['send_goods'])){
			// 赠送
			$send  = '赠送项目';
			$send .= '<table><tr><td>水煮花生</td><td>1</td><td>份</td><td>23</td><td>23</td></tr></table>';
			// $send .= '水煮花生 1 份 23 23';
			// $send .= '香酥炸薯条 1 份 23 23';
			$send .= '<center>----------------------------------------</center>';
			$send .= '<LR>送出金额,46</LR> ';
			$send .= '<center>----------------------------------------</center>';
		} else {
			$send = '<center>----------------------------------------</center>';
		}
		

		// count
		$count  = '<LR>项目总计:,'.$data['detail']['price'].'</LR>';
		$count .= '<table><tr><td>会员优惠:</td><td>xxx</td><td>xx%</td><td>-10</td></tr></table>';
		// $count .= '会员优惠: xxx xx% -10';
		$count .= '<center>----------------------------------------</center>';
		$count .= '<LR>应收：,'.$data['detail']['receive_price'].'</LR> ';
		$count .= '<center>----------------------------------------</center>';

		// footer 
		// $footer  = '<LR>付款方式 实收金额 找零金额 说明,</LR>';
		$footer  = '<table>';
		$footer .= '<tr><td>付款方式</td><td>实收</td><td>找零</td><td>说明</td></tr>';
		$footer .= '<tr><td>'.$data['detail']['pay_type'].'</td><td>'.$data['detail']['receive_price'].'</td><td>'.$data['detail']['refund_price'].'</td><td>'.$data['detail']['cashier'].'</td></tr>';
		$footer .= '</table>';
		// $footer .= '<table><tr>';
		// $footer .= '<td>'.$data['detail']['pay_type'].'</td>';
		// $footer .= '<td>'.$data['detail']['receive_price'].'</td>';
		// $footer .= '<td>'.$data['detail']['refund_price'].'</td>';
		// $footer .= '<td>'.$data['detail']['cashier'].'</td>';
		// $footer .= '</tr></table>';

		return  $heads . $room . $order . $count . $footer;
	}
	
	// [测试数据]文本主体
	public function FrontContentTest($data = [])
	{
		// 头部<LR>,</LR>
		// <table><tr><td>列1</td><td>列2</td><td>列3</td><td>列4</td><td>列5</td></tr></table>
		$heads  = '<LR>@@2门店名称,2020/11/9 12:00</LR>';
		$heads .= '<LR>人 数:13,订房人员:阿伟</LR>';
		$heads .= '<LR>账单编号:12345678910,结账人员:阿伟</LR>';
		$heads .= '<LR>卡 头 号:123456,打印次数:2</LR>';
		$heads .= '<LR>消费时长:4小时0分钟,房型:普通中型</LR>';
		$heads .= '<LR>日期:2020/11月/9日,时间:12:00-13:00</LR>';
		$heads .= '<center>----------------------------------------</center>';
		$heads .= '<table><tr><td>项目</td><td>数量</td><td>单位</td><td>价格</td><td>金额</td></tr></table>';
		$heads .= '<center>----------------------------------------</center>';
		$heads .= '<LR>酒水包段,12:00-13:00 1000</LR>';
		$heads .= '<center>----------------------------------------</center>';

		// 房费小计
		$room  = '<LR>房费小计:, 1000</LR>';
		// 消费小计
		$order = '<center>----------------------------------------</center>';
		$order .= '<table><tr><td>哈尔冰/百威2打</td><td>1</td><td>套</td><td>0</td><td>46</td></tr></table>';
		// $order .= '哈尔冰/百威2打 1 套 0 0';
		// $order .= '百威（罐）24 罐 16 46' ;
		$order .= '<center>----------------------------------------</center>';
		$order .= '<LR>消费小计,46</LR> ';
		$order .= '<center>----------------------------------------</center>';
		
		// 赠送
		$send  = '赠送项目';
		$send .= '<table><tr><td>水煮花生</td><td>1</td><td>份</td><td>23</td><td>23</td></tr></table>';
		// $send .= '水煮花生 1 份 23 23';
		// $send .= '香酥炸薯条 1 份 23 23';
		$send .= '<center>----------------------------------------</center>';
		$send .= '<LR>送出金额,46</LR> ';
		$send .= '<center>----------------------------------------</center>';

		// count
		$count  = '<LR>项目总计:,1046</LR>';
		$count .= '<table><tr><td>会员优惠:</td><td>xxx</td><td>xx%</td><td>-10</td></tr></table>';
		// $count .= '会员优惠: xxx xx% -10';
		$count .= '<center>----------------------------------------</center>';
		$count .= '<LR>应收：,1036</LR> ';
		$count .= '<center>----------------------------------------</center>';

		// footer 
		$footer  = '<LR>付款方式 实收金额 找零方式 找零金额 说明,</LR>';
		$footer .= '<LR>'.$data['pay_type'].' '.$data['receive_price'].' 人民币 0.00 '.$data['cashier'].',</LR>';

		return  $heads . $room . $order . $count . $footer;
	}
}